package com.clotingshoppos.modules.product.controller;

import com.clotingshoppos.modules.product.entity.ProductDataDictionaryEntity;
import com.clotingshoppos.modules.product.service.ProductDDService;
import com.clotingshoppos.common.util.RetResponse;
import com.clotingshoppos.common.util.RetResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * @ClassName: ProductDDContrller
 * @Description: 产品数据字典Controller层
 * @Author: zhandad
 * @Date: 2019-03-23 19:14
 * @Version: v1.0
 */
@RestController
@RequestMapping("/ProductDD")
public class ProductDDContrller {
    @Autowired
    private ProductDDService productDDService;

    @RequestMapping("/add")
    /**
    * @Description: 增加一个产品属性
    * @Param: [productDataDictionaryEntity]
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductDataDictionaryEntity>
    * @Author: zhandad
    * @Date: 2019/3/24  21:13
    */
    public RetResult<ProductDataDictionaryEntity> add(@RequestBody ProductDataDictionaryEntity productDataDictionaryEntity){
        ProductDataDictionaryEntity ProductDD = productDDService.addtoPDD(productDataDictionaryEntity);
        return RetResponse.makeOKRsp(ProductDD);
    }

    @RequestMapping("/delete")
    /**
    * @Description: 删除一个产品属性
    * @Param: [productDataDictionaryEntity]
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductDataDictionaryEntity>
    * @Author: zhandad
    * @Date: 2019/3/24  21:21
    */
    public RetResult<ProductDataDictionaryEntity> delete(@RequestBody ProductDataDictionaryEntity productDataDictionaryEntity){
        ProductDataDictionaryEntity productDD = productDDService.delete(productDataDictionaryEntity);
        return RetResponse.makeOKRsp(productDD);
    }

    @RequestMapping("/findByType")
    /**
    * @Description: 查找某一类别的属性
    * @Param: [productDataDictionaryEntity]
    * @return: com.clotingshoppos.util.RetResult<java.util.List<com.clotingshoppos.modules.product.entity.ProductDataDictionaryEntity>>
    * @Author: zhandad
    * @Date: 2019/3/24  21:27
    */
    public RetResult<List<ProductDataDictionaryEntity>> findByType(@RequestBody ProductDataDictionaryEntity productDataDictionaryEntity){
        List<ProductDataDictionaryEntity> list = productDDService.findByForm(productDataDictionaryEntity.getForm());
        return RetResponse.makeOKRsp(list);
    }

    @RequestMapping("/findById")
    /**
    * @Description: 按照id查找某一个属性
    * @Param: [productDataDictionaryEntity]
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductDataDictionaryEntity>
    * @Author: zhandad
    * @Date: 2019/3/24  21:30
    */
    public RetResult<Optional<ProductDataDictionaryEntity>> findById(@RequestBody ProductDataDictionaryEntity productDataDictionaryEntity){
        Optional<ProductDataDictionaryEntity> productDD = productDDService.findByPDDId(productDataDictionaryEntity.getId());
        return RetResponse.makeOKRsp(productDD);
    }

    @RequestMapping("/update")
    /**
    * @Description: 更新某一属性
    * @Param: [productDataDictionaryEntity]
    * @return: com.clotingshoppos.util.RetResult<com.clotingshoppos.modules.product.entity.ProductDataDictionaryEntity>
    * @Author: zhandad
    * @Date: 2019/3/24  21:32
    */
    public RetResult<ProductDataDictionaryEntity> update(@RequestBody ProductDataDictionaryEntity productDataDictionaryEntity){
        ProductDataDictionaryEntity productDD = productDDService.update(productDataDictionaryEntity);
        return RetResponse.makeOKRsp(productDD);
    }
}
